# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface


class FacebookPipeline(object):
    def __init__(self):
        super(FacebookPipeline, self).__init__()
        self.items = []

    def process_item(self, item, spider):
        self.items.append(item)
        if len(self.items) >= 5:
            self.upload_current_items()
        return item

    def upload_current_items(self):
        items = self.items
        self.items = []
        # self.insert_to_database(items)
        print("发送请求%s" % items)

    def close_spider(self, spider):
        self.upload_current_items()
